import { login } from '@/api/user'
import { getToken, setToken } from '@/utils/auth'

const state = {
  token: getToken() || ''
}

const mutations = {
  setToken(state, value) {
    state.token = value
    setToken(value)
  }
}

const actions = {
  async toLogin({ commit }, value) {
    const res = await login(value)
    commit('setToken', res.data)
    console.log(res)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
